{template "header.html"}


<script type="text/javascript">
    $(function(){
        dr_dw({intval($valuation)});
    });
    function dr_dw(id) {
        if (id==1) {
            $('.dr_dw').html('件');
            $('.dr_free_1').html('满');
            $('.dr_free_2').html('');
            $('.dr_name').html('数量');
            return '';
        }
        if (id==2) {
            $('.dr_dw').html('kg');
            $('.dr_free_1').html('在');
            $('.dr_free_2').html('内');
            $('.dr_name').html('重量');
            return;
        }
        if (id==3) {
            $('.dr_dw').html('m³');
            $('.dr_free_1').html('在');
            $('.dr_free_2').html('内');
            $('.dr_name').html('体积');
            return;
        }
    }
    function dr_remove_city(obj, id, city) {
        $("#dr_city_value_"+id).val('0');
        $(obj).remove();
    }

    function dr_city(id) {
        var url = "{dr_url('store/shipping/city_index')}";
        layer.open({
            type: 2,
            title: "选择城市",
            fix:true,
            scrollbar: false,
            shadeClose: true,
            shade: 0,
            area: ['40%', '40%'],
            btn: [lang['ok']],
            yes: function(index, layero){
                var body = layer.getChildFrame('body', index);
                $(body).find('.form-group').removeClass('has-error');
                // 延迟加载
                var loading = layer.load(2, {
                    shade: [0.3,'#fff'], //0.1透明度的白色背景
                    time: 10000
                });
                $.ajax({type: "POST",dataType:"json", url: url, data: $(body).find('#myform').serialize(),
                    success: function(json) {
                        layer.closeAll();
                        $("#dr_city_value_"+id).val(json.code);
                        $("#dr_city_html_"+id).html(' <a href="javascript:;" class="btn btn-xs red" onclick="dr_remove_city(this, '+id+', \''+json.code+'\')">'+json.msg+' <i class="fa fa-times"></i></a>');
                        return true;
                    },
                    error: function(HttpRequest, ajaxOptions, thrownError) {
                        layer.closeAll('loading');
                        alert(HttpRequest.responseText);
                    }
                });
                return false;
            },
            content: url+'&is_ajax=1'
        });
        return;
    }

    var freight_id = {intval($freight_id)};
    function dr_add_freight() {
        var id = freight_id;
        var html = '<tr id="dr_row_'+id+'">';
        html+= '<td style="text-align:left" class=""><label><a href="javascript:dr_city('+id+');" class="btn btn-xs green">[选择城市]</a></label><label id="dr_city_html_'+id+'"><a href="javascript:;" class="btn btn-xs red" onclick="dr_remove_city(this, '+id+', 0)">全国地区 <i class="fa fa-times"></i></a></label><input name="data[freight]['+id+'][city]" id="dr_city_value_'+id+'" type="hidden" value="0" /></td>';
        html+= '<td style="text-align:center"><input type="text" name="data[freight]['+id+'][start]" value="" class="form-control" /></td>';
        html+= '<td style="text-align:center"><input type="text" name="data[freight]['+id+'][postage]" value="" class="form-control" /></td>';
        html+= '<td style="text-align:center"><input type="text" name="data[freight]['+id+'][plus]" value="" class="form-control" /></td>';
        html+= '<td style="text-align:center"><input type="text" name="data[freight]['+id+'][postageplus]" value="" class="form-control" /></td>';
        html+= '<td style="text-align:center"><a href="javascript:$(\'#dr_row_'+id+'\').remove();" class="btn btn-xs red"> <i class="fa fa-trash"></i> </a></td>';
        html+= '</tr>';
        $("#dr_freight").append(html);
        freight_id ++ ;
    }


    function dr_remove_free_city(obj, id, city) {

        $("#dr_free_city_value_"+id).val('0');
        $(obj).remove();
    }

    function dr_free_city(id) {

        var url = "{dr_url('store/shipping/city_index')}";
        layer.open({
            type: 2,
            title: "选择城市",
            fix:true,
            scrollbar: false,
            shadeClose: true,
            shade: 0,
            area: ['40%', '40%'],
            btn: [lang['ok']],
            yes: function(index, layero){
                var body = layer.getChildFrame('body', index);
                $(body).find('.form-group').removeClass('has-error');
                // 延迟加载
                var loading = layer.load(2, {
                    shade: [0.3,'#fff'], //0.1透明度的白色背景
                    time: 10000
                });
                $.ajax({type: "POST",dataType:"json", url: url, data: $(body).find('#myform').serialize(),
                    success: function(json) {
                        layer.closeAll();
                        $("#dr_free_city_value_"+id).val(json.code);
                        $("#dr_free_city_"+id).html(' <a href="javascript:;" class="btn btn-xs red" onclick="dr_remove_free_city(this, '+id+', \''+json.code+'\')">'+json.msg+' <i class="fa fa-times"></i></a>');
                        return true;
                    },
                    error: function(HttpRequest, ajaxOptions, thrownError) {
                        layer.closeAll('loading');
                        alert(HttpRequest.responseText);
                    }
                });
                return false;
            },
            content: url+'&is_ajax=1'
        });
        return;
    }

    var free_id = {intval($free_id)};
    function dr_add_free() {
        var id = free_id;
        var html = '<tr id="dr_free_row_'+id+'">';
        html+= '<td style="text-align:left"><label><a href="javascript:dr_free_city('+id+');"  class="btn btn-xs green">[选择城市]</a></label> <label id="dr_free_city_'+id+'"><a href="javascript:;" title="删除" onclick="dr_remove_free_city(this, '+id+', \'0\')" class="btn btn-xs red">全国地区 <i class="fa fa-times"></i></a></label><input name="data[free]['+id+'][city]" id="dr_free_city_value_'+id+'" type="hidden" value="0" /></td>';
        html+= '<td class="fc-mall-free-value" style="text-align:left">';
        html+= '<p><label><input type="radio" name="data[free]['+id+'][type]" value="1"></label> <label class="dr_free_1"></label> <label><input type="text" name="data[free]['+id+'][1]" style="width: 50px" class="form-control" /></label><label class="dr_dw"></label><label class="dr_free_2"></label><label>包邮</label></p>';
        html+= '<p><label><input type="radio" name="data[free]['+id+'][type]" value="2"></label> <label>满</label> <label><input type="text" name="data[free]['+id+'][2]" style="width: 50px" class="form-control" /></label> <label>元包邮</label></p>';
        html+= '<p><label><input type="radio" name="data[free]['+id+'][type]" value="3"></label> <label class="dr_free_1"></label> <label><input type="text" name="data[free]['+id+'][3][dw]" style="width: 50px" class="form-control" /></label><label class="dr_dw"></label><label class="dr_free_2"></label><label>，&nbsp;满&nbsp;</label><label><input type="text" name="data[free]['+id+'][3][price]"  style="width: 90px" class="form-control" /></label><label>&nbsp;元包邮</label></p>';
        html+= '</td>';
        html+= '<td><a href="javascript:$(\'#dr_free_row_'+id+'\').remove();"  class="btn btn-xs red"> <i class="fa fa-trash"></i> </a></td>';
        html+= '</tr>';
        $("#dr_free").append(html);
        free_id ++ ;
        dr_dw($('input:radio[name="data[valuation]"]:checked').val());
    }
</script>
<style>
    .color-box {
        width: 12px;
        height: 12px;
        display: inline-block;
        margin: 0 3px;
        position: relative;
        top: 3px;
        border: 1px solid #ddd;
    }
    .fc-mall-sku-style th {
        background-color: #EDEDED;
        border: 1px solid #D7D7D7 !important;
        font-weight: 400;
        height: 25px;
        text-align: center;
        vertical-align: middle;
        padding:0;
    }
    .fc-mall-sku-style td {
        border: 1px solid #D7D7D7 !important;
        padding: 3px 5px;
        text-align: center;
        vertical-align: middle;
        height: 25px;
        min-width: 60px;
    }
    .fc-mall-mryf {
        padding: 10px 15px 5px;
        margin-top: 5px;
        margin-bottom: 10px;
        background-color: #f3feed;
    }
    .fc-mall-free-value p {
        margin:0;
        padding-top: 5px;
    }
</style>

<form action="" class="form-horizontal" method="post" name="myform" id="myform">
    {$form}
    <div class="portlet bordered light myfbody">
        <div class="portlet-title">
            <div class="caption">
                <span class="caption-subject font-green-sharp">
                    {dr_lang('运费策略')}
                </span>
            </div>
            <div class="actions">
                <div class="btn-group">
                    <a class="btn" href="{$reply_url}"> <i class="fa fa-mail-reply"></i> {dr_lang('返回')}</a>
                </div>
            </div>
        </div>
        <div class="portlet-body">
            <div class="form-body">

                <div class="form-group dr_one" id="dr_row_name">
                    <label class="col-md-2 control-label">{dr_lang('名称')}</label>
                    <div class="col-md-4">
                        <input type="text" class="form-control" id="dr_name" name="data[name]" value="{$name}">
                        <span class="help-block"> {dr_lang('它的描述名称')} </span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">{dr_lang('计价方式')}</label>
                    <div class="col-md-9">
                        <div class="mt-radio-inline">
                            <label class="mt-radio mt-radio-outline"><input type="radio" onclick="dr_dw(1)" name="data[valuation]" value="1" {if $valuation == 1}checked{/if} /> {dr_lang('按数量')} <span></span></label>
                            <label class="mt-radio mt-radio-outline"><input type="radio" onclick="dr_dw(2)" name="data[valuation]" value="2" {if $valuation == 2}checked{/if} /> {dr_lang('按重量')} <span></span></label>
                            <label class="mt-radio mt-radio-outline"><input type="radio" onclick="dr_dw(3)" name="data[valuation]" value="3" {if $valuation == 3}checked{/if} /> {dr_lang('按体积')} <span></span></label>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-2 control-label">{dr_lang('运费详情')}</label>
                    <div class="col-md-9">

                        <div class="fc-mall-mryf">
                            <label>默认运费：</label>
                            <label><input type="text" name="data[freight][default][start]" value="{$freight['default']['start']}" style="width:50px" class="form-control" /></label>
                            <label><span class="dr_dw">单位</span>内，</label>
                            <label><input type="text" name="data[freight][default][postage]" value="{$freight['default']['postage']}" style="width:50px" class="form-control" /></label>
                            <label>元，每增加</label>
                            <label><input type="text" name="data[freight][default][plus]" value="{$freight['default']['plus']}" style="width:50px" class="form-control" /></label>
                            <label><span class="dr_dw">单位</span>，增加运费</label>
                            <label><input type="text" name="data[freight][default][postageplus]" value="{$freight['default']['postageplus']}" style="width:50px" class="form-control" /></label>
                            <label>元</label>
                        </div>
                        <table class="fc-mall-sku-style table fc-head-table table-mtotal  table-bordered table-striped table-bordered">
                            <thead>
                            <tr>
                                <th>运送到</th>
                                <th width=110>首<span class="dr_name"></span>(<span class="dr_dw"></span>)</th>
                                <th width=110>首费(元)</th>
                                <th width=110>续<span class="dr_name"></span>(<span class="dr_dw"></span>)</th>
                                <th width=110>续费(元)</th>
                                <th width=40></th>
                            </tr>
                            </thead>
                            <tbody id="dr_freight">
                            {php unset($freight['default']);}
                            {loop $freight $i $t}
                            <tr id="dr_row_{$i}">
                                <td style="text-align:left">
                                    <label><a href="javascript:dr_city({$i});"  class="btn btn-xs green">[选择城市]</a></label>
                                    <label id="dr_city_html_{$i}">
									{if $t.city}
                                        <a href="javascript:;" class="btn btn-xs red" onclick="dr_remove_city(this, {$i}, {$t.city})">{dr_linkagepos(FC_ADDRESS_CITY, $t.city, ' » ')} <i class="fa fa-times"></i></a>
									{else}
                                        <a href="javascript:;" class="btn btn-xs red" onclick="dr_remove_city(this, {$i}, 0)">全国地区 <i class="fa fa-times"></i></a>
									{/if}
								    </label>
                                    <input name="data[freight][{$i}][city]" id="dr_city_value_{$i}" type="hidden" value="{$t.city}" />
                                </td>
                                <td><input type="text" name="data[freight][{$i}][start]" value="{$t.start}"  class="form-control" /></td>
                                <td><input type="text" name="data[freight][{$i}][postage]" value="{$t.postage}"  class="form-control" /></td>
                                <td><input type="text" name="data[freight][{$i}][plus]" value="{$t.plus}"  class="form-control" /></td>
                                <td><input type="text" name="data[freight][{$i}][postageplus]" value="{$t.postageplus}"  class="form-control" /></td>
                                <td><a href="javascript:$('#dr_row_{$i}').remove();" class="btn btn-xs red"> <i class="fa fa-trash"></i> </a></td>
                            </tr>
                            {/loop}
                            </tbody>
                        </table>
                        <a href="javascript:;" onclick="dr_add_freight()" class="btn btn-xs green"> <i class="fa fa-plus"></i> 为指定地区城市设置运费</a>
                    </div>
                </div>


                <div class="form-group">
                    <label class="col-md-2 control-label">{dr_lang('包邮策略')}</label>
                    <div class="col-md-9">
                        <table class="fc-mall-sku-style table fc-head-table table-mtotal  table-bordered table-striped table-bordered">
                        <thead>
                            <tr>
                                <th>运送到</th>
                                <th>设置包邮条件</th>
                                <th width=40></th>
                            </tr>
                            </thead>
                            <tbody id="dr_free">
                            {loop $free $i $t}
                            <tr id="dr_free_row_{$i}">
                                <td style="text-align:left">
                                    <label><a href="javascript:dr_free_city({$i});"  class="btn btn-xs green">[选择城市]</a></label>
                                    <label id="dr_free_city_{$i}">
                                        {if $t.city}
                                        <a href="javascript:;" class="btn btn-xs red" onclick="dr_remove_free_city(this, {$i}, {$t.city})">{dr_linkagepos(FC_ADDRESS_CITY, $t.city, ' » ')} <i class="fa fa-times"></i></a>
                                        {else}
                                        <a href="javascript:;" class="btn btn-xs red" onclick="dr_remove_free_city(this, {$i}, 0)">全国地区 <i class="fa fa-times"></i></a>
                                        {/if}
								    </label>
                                    <input name="data[free][{$i}][city]" id="dr_free_city_value_{$i}" type="hidden" value="{$t.city}" />
                                </td>
                                <td class="fc-mall-free-value" style="text-align:left">
                                    <p><label><input type="radio" name="data[free][{$i}][type]" {if $t.type==1}checked{/if} value="1"></label> <label class="dr_free_1"></label> <label><input type="text" name="data[free][{$i}][1]" value="{$t[1]}" style="width:50px" class="form-control" /></label> <label class="dr_dw"></label><label class="dr_free_2"></label><label>包邮</label></p>
                                    <p><label><input type="radio" name="data[free][{$i}][type]" {if $t.type==2}checked{/if} value="2"></label> <label>满&nbsp;</label><label><input type="text" name="data[free][{$i}][2]" value="{$t[2]}" style="width:50px" class="form-control" /> </label> <label>元包邮</label></p>
                                    <p><label><input type="radio" name="data[free][{$i}][type]" {if $t.type==3}checked{/if} value="3"></label> <label class="dr_free_1"></label> <label><input type="text" name="data[free][{$i}][3][dw]" value="{$t[3]['dw']}" style="width:50px" class="form-control" /></label><label class="dr_dw"></label><label class="dr_free_2"></label><label>，&nbsp;满&nbsp;</label><label><input type="text" name="data[free][{$i}][3][price]" value="{$t[3]['price']}" style="width:90px" class="form-control" /></label><label>元包邮</label></p>
                                </td>
                                <td><a href="javascript:$('#dr_free_row_{$i}').remove();" class="btn btn-xs red"> <i class="fa fa-trash"></i> </a></td>
                            </tr>
                            {/loop}
                            </tbody>
                        </table>
                        <a href="javascript:;" onclick="dr_add_free()" class="btn btn-xs green"> <i class="fa fa-plus"></i> 为指定地区城市包邮策略</a>
                    </div>
                </div>


            </div>
        </div>
    </div>

    <div class="portlet-body form myfooter">
        <div class="form-actions text-center">
            <button type="button" onclick="dr_ajax_submit('{dr_now_url()}', 'myform', '2000')" class="btn green"> <i class="fa fa-save"></i> {dr_lang('保存内容')}</button>
            <button type="button" onclick="dr_ajax_submit('{dr_now_url()}', 'myform', '2000', '{$post_url}')" class="btn blue"> <i class="fa fa-plus"></i> {dr_lang('保存再添加')}</button>
            <button type="button" onclick="dr_ajax_submit('{dr_now_url()}', 'myform', '2000', '{$reply_url}')" class="btn yellow"> <i class="fa fa-mail-reply-all"></i> {dr_lang('保存并返回')}</button>
        </div>
    </div>
</form>

{template "footer.html"}